<?php
  class TextField extends Component {
    private $text;
    private $type;
    private $label;
    
    function update($string) {
      $this->text = $string;
    }

    function show($id) {
      $html = "";
      if($this->label) $html .= "<label style=\"font-size:15px; color: #404040\">" . $this->label . "</label>";
      $html .= "<input id=\"" . $this->uuid . "_input\" type=\"" . $this->type . "\" value=\"" . $this->text . "\">";
      parent::show($id,$html);

      echo "el = document.getElementById('" . $this->uuid . "_input');\n";
      echo "el.style.background = '#ffffff';\n";
      echo "el.style.width = '100%';\n";
      echo "el.style.height = '" . ($this->height - 15) . "px';\n";
      echo "el.style.border = '1px solid #D9D9D9';\n";
      echo "el.style.fontSize = '" . ($this->height - 20) . "px';\n";
      echo "el.style.outline = 'none';\n";

      echo "el.onfocus = function() {\n";
      echo "  this.hasFocus=true;\n";
      echo "  this.style.border = '1px solid #4D90FE';\n";
      echo "}\n";      
      echo "el.onblur = function() {\n";
      echo "  this.hasFocus=false;\n";
      echo "  this.style.border = '1px solid #D9D9D9';\n";
      echo "}\n";        
      echo "el.onmouseover = function() {\n";
      echo "  if(!this.hasFocus) this.style.border = '1px solid #A0A0A0';\n";
      echo "}\n";
      echo "el.onmouseout = function() {\n";
      echo "  if(!this.hasFocus) this.style.border = '1px solid #D9D9D9';\n";
      echo "}\n";

      echo "F['" . $this->uuid . "'] = \"function() { return document.getElementById('" . $this->uuid . "_input').value; }\";\n";
      echo "\n";
    }
    function setText($text) {
      global $RUNSTATE;
      $this->text = $text;
      if($RUNSTATE=="javascript") {
        echo $this->uuid . "_setText('" . $text . "');\n";
      }
    }
    function getText() {
      return $this->text;
    }
    function getType() {
      return $this->type;
    }
    function setType($type) {
      $this->type = $type;
    }
    function setLabel($label) {
      $this->label = $label;
    }    
    function __construct($uuid,$text="",$label="text") {
      parent::__construct($uuid);
      $this->text = $text;
      $this->label = $label;
      $this->setStyle("cursor","text");
      $this->setBounds(20,40,200,45);
    }
  }

?>
